﻿using System.Threading;

namespace SearchRS
{
    public class WarezBBSearcher : SearchWithResultsPage
    {
        protected override INotifications NotificationsClient { get; set; }

        protected override string BaseURL
        {
            get { return "http://www.warez-bb.org"; }
        }

        protected override string SearchURL
        {
            get { return BaseURL + "/search.php"; }
        }

        protected override string LoginURL
        {
            get { return BaseURL + "/login.php"; }
        }

        protected override string SiteName
        {
            get { return "Warez-BB"; }
        }

        protected override string SidCookieParam
        {
            get
            {
                return
                    "phpBB_WBB_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bi%3A-1%3B%7D; phpBB_WBB_sid=9dbdb95d8810d4604d155095de8dbd80; __utma=128554762.495039684.1217054685.1227876354.1227876728.201; __utmz=128554762.1217054685.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmb=128554762.4.10.1227876728; __utmc=128554762";
            }
        }

        private string cookie;
        protected override string SearchCookieParam
        {
            get
            {
                return "phpBB_WBB_sid=" + Sid +
                       "; path=/;phpBB_WBB_fpass=deleted; expires=Wed, 21-Nov-2007 23:47:10 GMT; path=/;phpBB_WBB_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A6%3A%22808113%22%3B%7D; expires=Fri, 20-Nov-2009 23:47:11 GMT; path=/";
            }
            set
            {
                cookie = value;
            }

        }

        protected override string PageCookieParam
        {
            get
            {
                return "phpBB_WBB_sid=" + Sid +
                       "; path=/;phpBB_WBB_fpass=deleted; expires=Wed, 21-Nov-2007 23:47:10 GMT; path=/;phpBB_WBB_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A6%3A%22808113%22%3B%7D; expires=Fri, 20-Nov-2009 23:47:11 GMT; path=/";
            }
        }

        protected override string ResultTitleStartString
        {
            get { return "<span class=\"topictitle\"><a href=\"viewtopic.php"; }
        }

        protected override string ResultTitleFinishString
        {
            get { return "</a></span>"; }
        }

        protected override string TitleStartPosString
        {
            get { return "<span class=\"topictitle\"><a href=\"viewtopic.php"; }
        }

        protected override bool IsPost
        {
            get { return true; }
        }

        protected override string PostOrGetParams(bool searchAppsAndGamesAndEbooksToo)
        {
            return "search_keywords=" + m_searchString + "&search_terms=all&search_author=&" +
                   GetForumsString(searchAppsAndGamesAndEbooksToo) +
                   "&search_time=0&search_fields=titleonly&sort_by=0&sort_dir=DESC&show_results=topics&return_chars=200";
        }

        protected static string GetForumsString(bool searchAppsAndGamesAndEbooksToo)
        {
            return searchAppsAndGamesAndEbooksToo 
                ? "search_forum%5B%5D=3&search_forum%5B%5D=47&search_forum%5B%5D=5&search_forum%5B%5D=28&search_forum%5B%5D=4&search_forum%5B%5D=57&search_forum%5B%5D=88&search_forum%5B%5D=6&search_forum%5B%5D=8&search_forum%5B%5D=83&search_forum%5B%5D=20"
                : "search_forum%5B%5D=4&search_forum%5B%5D=57";
        }

        protected override string Sid { get; set; }

        public WarezBBSearcher(INotifications notificationsClient, SearchRsParams searchRsParams) :
            base(searchRsParams)
        {
            NotificationsClient = notificationsClient;
            SetSid();
        }
       
    }
}
